Jupyter上でC++を使って音声処理&デバッグがしたいね
#include <iostream>
std::cout << "hello world" << std::endl;
hello world
今回は簡単にAudioFileを利用して音声の情報参照
そして、nlohmann/jsonを利用して音声を再生
#include <string>
#include <fstream>
#include "nlohmann/json.hpp"
#include "xtl/xbase64.hpp"
namespace nl = nlohmann;
namespace au
{
struct audio
{
inline audio(const std::string& filename)
{
std::ifstream fin(filename, std::ios::binary);
m_buffer << fin.rdbuf();
}
std::stringstream m_buffer;
};
nl::json mime_bundle_repr(const audio& a)
{
auto bundle = nl::json::object();
bundle["text/html"] =
std::string("<audio controls=\"controls\"><source src=\"data:audio/wav;base64,")
+ xtl::base64encode(a.m_buffer.str()) +
"\" type=\"audio/wav\" /></audio>";
return bundle;
}
}
#pragma cling add_include_path("/notebooks/AudioFile")
#include <AudioFile.h>
AudioFile<double> audioFile;
audioFile.load ("demosound.wav");
audioFile.printSummary();
|======================================| Num Channels: 2 Num Samples Per Channel: 5373517 Sample Rate: 44100 Bit Depth: 16 Length in Seconds: 121.848 |======================================|
au::audio audioData("demosound.wav");
audioData